package org.nowcoder.leetcode.DP;

/**
 * Title  : 300. Longest Increasing Subsequence
 * Source : https://leetcode.cn/problems/longest-increasing-subsequence/
 * Author : XrazYang
 * Date   : 2023-11-14
 */

public class LeetCode_300 {
    public int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length]; //定义状态： dp[i] 表示以nums[i]结尾的最长上升子序列的长度
        dp[0] = 1;  //初始状态
        int len = 1;
        for (int i = 1; i < nums.length; i++) {
            dp[i] = 1;
            for (int j = 0; j < i; j++) { //状态转移方程
                if (nums[j] < nums[i]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
            len = Math.max(len, dp[i]);
        }
        return len;
    }
}
